/**
 * 安卓白金英雄坛制作组 <br>
 * 文件名：NetProperties.java <br>
 * 创建时间：2015年4月16日 上午11:17:25 <br>
 * 所属项目：GmudEX <br>
 *
 * @author 12548
 */
package lostland.gmud.exv2;

import cn.bmob.v3.BmobObject;
import cn.bmob.v3.BmobQuery;
import cn.bmob.v3.listener.GetListener;

public class NetProperties extends BmobObject {

	private static volatile boolean isFromNet = false;


	private volatile static NetProperties properties;

	private static final long serialVersionUID = 1175084965188323542L;

	public static NetProperties getProperties() {

		if (!isFromNet) {
			BmobQuery<NetProperties> q = new BmobQuery<>();
			q.getObject(Game.getInstance(), "gTn3999V", new GetListener<NetProperties>() {

				@Override
				public void onFailure(int arg0, String arg1) {
					isFromNet = false;
				}

				@Override
				public void onSuccess(NetProperties arg0) {
					synchronized (NetProperties.class) {
						properties = arg0;
						isFromNet = true;
					}
				}
			});
		}

		if (properties == null) {
			synchronized (NetProperties.class) {
				if (properties == null) {
					properties = new NetProperties();
					isFromNet = false;
				}
			}
		}

		return properties;
	}

	/**
	 * @return 表示数据是从网上获取的。
	 */
	public boolean isFromNet() {
		return isFromNet;
	}

	public static void setProperties(NetProperties properties) {
		NetProperties.properties = properties;
	}

	private boolean adEnabled = false;

	private NetProperties() {
	}

	public boolean isAdEnabled() {
		return adEnabled;
	}

	public void setAdEnabled(boolean adEnabled) {
		this.adEnabled = adEnabled;
	}

	;
}
